﻿using System;
using System.Windows;
using System.Timers;

namespace Utils
{

    public class Runnable
    {       
        public virtual void Run()
        {

        }
    }

    public class Timer
    {
        private System.Timers.Timer _timer;
        protected string _Name;

        public Runnable m_Runnable;

        public Timer()
        {
            _timer = new System.Timers.Timer();
        }


        public void Start()
        {
            _timer.Start();
        }

        public System.Timers.Timer GetTimer()
        {
            return _timer;
        }

        public void Stop()
        {
            if (_timer != null)
            {
                _timer.Stop();
            }
        }

        /// <summary>
        /// 定时器运行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Run(object sender, ElapsedEventArgs e)
        {
            m_Runnable.Run();
        }

        /// <summary>
        /// 注册定时器事件
        /// </summary>
        /// <param name="handler">定时器事件</param>
        /// <param name="Interval">间隔多少毫秒进行执行</param>
        /// <param name="isAutoReset">是否一直循环</param>
        public void Register(Runnable handler, float Interval, bool isAutoReset = false)
        {
            m_Runnable = handler;
            _timer.Elapsed += Run;
            _timer.Interval = Interval;
            _timer.AutoReset = isAutoReset;
        }
    }

    /// <summary>
    /// Ping定时器
    /// </summary>
    public class PingTimer : Timer
    {
        private static PingTimer instance = new PingTimer();

        private PingTimer()
        {
            this._Name = "Pingtimer";
        }

        public static PingTimer getInstance()
        {
            return instance;
        }
    }

    /// <summary>
    /// 事件定时器
    /// </summary>
    public class EventTimer : Timer
    {
        private static EventTimer instance = new EventTimer();

        private EventTimer()
        {
            this._Name = "EventTimer";
        }

        public static EventTimer getInstance()
        {
            return instance;
        }
    }


    /// <summary>
    /// Buff定时器
    /// </summary>
    public class BuffTimer : Timer
    {
        private static BuffTimer instance = new BuffTimer();

        private BuffTimer()
        {
            this._Name = "BuffTimer";
        }

        public static BuffTimer getInstance()
        {
            return instance;
        }
    }


    /// <summary>
    /// 冒险岛通用定时器
    /// </summary>
    public class MapTimer : Timer
    {
        private static MapTimer instance = new MapTimer();

        private MapTimer()
        {
            this._Name = "MapTimer";
        }

        public static MapTimer getInstance()
        {
            return instance;
        }
    }


    /// <summary>
    /// 世界定时器
    /// </summary>
    public class WorldTimer : Timer
    {
        private static WorldTimer instance = new WorldTimer();

        private WorldTimer()
        {
            this._Name = "WorldTimer";
        }

        public static WorldTimer getInstance()
        {
            return instance;
        }
    }




} // namespace